package com.lagou;

import com.lagou.service.Method;

import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

/**
 * @author zy
 * @version 1.0
 * @date 2021/2/27 23:49
 */
public class RandomMathod implements Runnable {

    private final Method method;

    public RandomMathod(Method method) {
        this.method = method;
    }

    @Override
    public void run() {
        try {
            TimeUnit.MILLISECONDS.sleep(30);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        final int i = ThreadLocalRandom.current().nextInt(3);
        String result = null;
        switch (i) {
            case 0:
                result = method.methodA("");
                break;
            case 1:
                result = method.methodB("");
                break;
            case 2:
                result = method.methodC("");
                break;
            default:
                break;

        }
        // 调用结果
        System.out.println(Thread.currentThread().getName() + " result = " + Objects.toString(result, ""));
    }
}
